package com.galeno.day02;

import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.functions.source.RichSourceFunction;

import java.util.Random;

/**
 * @author galeno
 * @Title:
 * @Description:
 * @date 2021/10/1617:50
 */
public class NoParallSourceFunc2 extends RichSourceFunction<String> {

    @Override
    public void open(Configuration parameters) throws Exception {
        System.out.println("Open方法被调用***********");
    }

    @Override
    public void close() throws Exception {
        System.out.println("Close方法被调用**********");
    }


    @Override
    public void run(SourceContext<String> sourceContext) throws Exception {
        Random random = new Random();

        while (true) {
            int i = random.nextInt(100);
            sourceContext.collect(i+"");
            Thread.sleep(1000);
        }
    }

    @Override
    public void cancel() {
        System.out.println("cancel方法被调用了");
    }
}
